home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / dos / namefromlock.c < prev    next >
C/C++ Source or Header  |  1996-09-13  |  5KB  |  200 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: namefromlock.c,v 1.5 1996/09/13 17:50:07 digulla Exp $
  4.     $Log: namefromlock.c,v $
  5.     Revision 1.5  1996/09/13 17:50:07  digulla
  6.     Use IPTR
  7.  
  8.     Revision 1.4  1996/08/13 13:52:49  digulla
  9.     Replaced <dos/dosextens.h> by "dos_intern.h" or added "dos_intern.h"
  10.     Replaced __AROS_LA by __AROS_LHA
  11.  
  12.     Revision 1.3  1996/08/12 14:20:38  digulla
  13.     Added aliases
  14.  
  15.     Revision 1.2  1996/08/01 17:40:55  digulla
  16.     Added standard header for all files
  17.  
  18.     Desc:
  19.     Lang: english
  20. */
  21. #include <clib/exec_protos.h>
  22. #include <dos/exall.h>
  23. #include <dos/filesystem.h>
  24. #include "dos_intern.h"
  25.  
  26. /*****************************************************************************
  27.  
  28.     NAME */
  29.     #include <clib/dos_protos.h>
  30.  
  31.     __AROS_LH3(BOOL, NameFromLock,
  32.  
  33. /*  SYNOPSIS */
  34.     __AROS_LHA(BPTR,   lock,   D1),
  35.     __AROS_LHA(STRPTR, buffer, D2),
  36.     __AROS_LHA(LONG,   length, D3),
  37.  
  38. /*  LOCATION */
  39.     struct DosLibrary *, DOSBase, 67, Dos)
  40.  
  41. /*  FUNCTION
  42.     Get the full path name associated with a lock to a file or
  43.     directory into a user supplied buffer.
  44.  
  45.     INPUTS
  46.     lock   - Lock to file or directory.
  47.     buffer - Buffer to fill. Contains a NUL terminated string if
  48.          all went well.
  49.     length - Size of the buffer in bytes.
  50.  
  51.     RESULT
  52.     !=0 if all went well, 0 in case of an error. IoErr() will
  53.     give additional information in that case.
  54.  
  55.     NOTES
  56.  
  57.     EXAMPLE
  58.  
  59.     BUGS
  60.  
  61.     SEE ALSO
  62.  
  63.     INTERNALS
  64.  
  65.     HISTORY
  66.     29-10-95    digulla automatically created from
  67.                 dos_lib.fd and clib/dos_protos.h
  68.  
  69. *****************************************************************************/
  70.  
  71. /*****************************************************************************
  72.  
  73.     NAME
  74.     #include <clib/dos_protos.h>
  75.  
  76.     __AROS_LH3(LONG, NameFromFH,
  77.  
  78.     SYNOPSIS
  79.     __AROS_LHA(BPTR  , fh, D1),
  80.     __AROS_LHA(STRPTR, buffer, D2),
  81.     __AROS_LHA(long  , len, D3),
  82.  
  83.     LOCATION
  84.     struct DosLibrary *, DOSBase, 68, Dos)
  85.  
  86.     FUNCTION
  87.     Get the full path name associated with file-handle into a
  88.     user supplied buffer.
  89.  
  90.     INPUTS
  91.     fh     - File-handle to file or directory.
  92.     buffer - Buffer to fill. Contains a NUL terminated string if
  93.          all went well.
  94.     length - Size of the buffer in bytes.
  95.  
  96.     RESULT
  97.     !=0 if all went well, 0 in case of an error. IoErr() will
  98.     give additional information in that case.
  99.  
  100.     NOTES
  101.  
  102.     EXAMPLE
  103.  
  104.     BUGS
  105.  
  106.     SEE ALSO
  107.  
  108.     INTERNALS
  109.  
  110.     HISTORY
  111.     29-10-95    digulla automatically created from
  112.                 dos_lib.fd and clib/dos_protos.h
  113.  
  114. *****************************************************************************/
  115. /*AROS alias NameFromFH NameFromLock */
  116. {
  117.     __AROS_FUNC_INIT
  118.     __AROS_BASE_EXT_DECL(struct DosLibrary *,DOSBase)
  119.  
  120.     STRPTR s1, s2, name;
  121.     struct Unit *curlock, *oldlock=NULL;
  122.     struct ExAllData *ead=(struct ExAllData *)buffer;
  123.     LONG error;
  124.  
  125.     /* Get pointer to filehandle */
  126.     struct FileHandle *fh=(struct FileHandle *)BADDR(lock);
  127.  
  128.     /* Get pointer to process structure */
  129.     struct Process *me=(struct Process *)FindTask(NULL);
  130.  
  131.     /* Get pointer to I/O request. Use stackspace for now. */
  132.     struct IOFileSys io,*iofs=&io;
  133.  
  134.     /* Prepare I/O request. */
  135.     iofs->IOFS.io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  136.     iofs->IOFS.io_Message.mn_ReplyPort     =&me->pr_MsgPort;
  137.     iofs->IOFS.io_Message.mn_Length     =sizeof(struct IOFileSys);
  138.     iofs->IOFS.io_Device= fh==NULL?DOSBase->dl_NulHandler:fh->fh_Device;
  139.  
  140.     /* Construct the name from top to bottom */
  141.     name=buffer+length;
  142.     *--name=0;
  143.     curlock= fh==NULL?DOSBase->dl_NulLock:fh->fh_Unit;
  144.     /* Loop over path */
  145.     do
  146.     {
  147.     /* Read name of current lock (into the user supplied buffer) */
  148.     iofs->IOFS.io_Unit=curlock;
  149.     iofs->IOFS.io_Command=FSA_EXAMINE;
  150.     iofs->io_Args[0]=(IPTR)buffer;
  151.     iofs->io_Args[1]=name-buffer;
  152.     iofs->io_Args[2]=ED_TYPE;
  153.     DoIO(&iofs->IOFS);
  154.     error=iofs->io_DosError;
  155.  
  156.     /* Move name to the top of the buffer. */
  157.     if(!error)
  158.     {
  159.         s1=s2=ead->ed_Name;
  160.         while(*s2++)
  161.         ;
  162.         if(ead->ed_Type==ST_ROOT)
  163.         *--name=':';
  164.         else if(oldlock!=NULL)
  165.         *--name='/';
  166.         s2--;
  167.         while(s2>s1)
  168.         *--name=*--s2;
  169.     }
  170.  
  171.     /* Read the parent's lock (if there is a parent) */
  172.     if(!error&&ead->ed_Type!=ST_ROOT)
  173.     {
  174.         iofs->IOFS.io_Command=FSA_OPEN;
  175.         iofs->io_Args[0]=(IPTR)"/";
  176.         iofs->io_Args[1]=0;
  177.         DoIO(&iofs->IOFS);
  178.         curlock=iofs->IOFS.io_Unit;
  179.         error=iofs->io_DosError;
  180.     }
  181.  
  182.     /* Free the old lock if it was allocated by NameFromLock(). */
  183.     if(oldlock!=NULL)
  184.     {
  185.         iofs->IOFS.io_Unit=oldlock;
  186.         iofs->IOFS.io_Command=FSA_CLOSE;
  187.         DoIO(&iofs->IOFS);
  188.     }
  189.     oldlock=curlock;
  190.     }while(!error&&ead->ed_Type!=ST_ROOT);
  191.  
  192.     /* Move the name from the top to the bottom of the buffer. */
  193.     while((*buffer++=*name++)!=0)
  194.     ;
  195.     /* All done. */
  196.     me->pr_Result2=error;
  197.     return !error;
  198.     __AROS_FUNC_EXIT
  199. } /* NameFromLock */
  200.